$(function (){
   if(error){
      layer.msg(error);
   }
   $("#sub-btn").click(function (){
      remember();
   });
   let rememberState =localStorage.getItem("remember");
   if(rememberState){
      let username =localStorage.getItem("username");
      if(username){
         $(":input[name = username]").val(username);
      }
      let password = localStorage.getItem("password");
      if(password){
         $(":input[name = password]").val(password);
      }
   }
   $("#captcha").click(function (){
      $(this).attr("src",ctx+"/user/captcha?k=" + new Date().getTime());
   });

});
function  remember() {
   let state = $("#remember").prop("checked");
   if (state){
      let username = $(":input[name=username]").val();
      let password = $(":input[name=password]").val();
      console.log(username+" "+password);
      localStorage.setItem("remember","true");
      localStorage.setItem("username",username);
      localStorage.setItem("password",password);
   }
   else{
      localStorage.removeItem("remember");
      localStorage.removeItem("username");
      localStorage.removeItem("password");
   }
   $("#login-form").submit();

}